<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>Pandas数据规整-合并 | Python 数据分析学习目录</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../数据分析库的操作/13Pandas数据规整-重塑和轴向旋转.html" />
    
    
    <link rel="prev" href="../数据分析库的操作/14Pandas数据规整-转换-离散化和面元划分.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="4.4.8"
        data-chapter-title="Pandas数据规整-合并"
        data-filepath="数据分析库的操作/16Pandas数据规整-合并.md"
        data-basepath=".."
        data-revision="Wed Oct 24 2018 21:30:49 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        数据分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="Python数据分析序言/内容序言.html">
            
                
                    <a href="../Python数据分析序言/内容序言.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        Python数据分析内容
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2" data-path="python数据分析环境和工具/Python数据分析相关.html">
            
                
                    <a href="../python数据分析环境和工具/Python数据分析相关.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        python数据分析环境和工具
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="python数据分析环境和工具/1Python数据课程软件和环境安装.html">
            
                
                    <a href="../python数据分析环境和工具/1Python数据课程软件和环境安装.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        Python数据课程 软件和环境安装
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="python数据分析环境和工具/2python发行版.html">
            
                
                    <a href="../python数据分析环境和工具/2python发行版.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        python发行版
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="python数据分析环境和工具/5交互式编辑器-JupyterNotebook.html">
            
                
                    <a href="../python数据分析环境和工具/5交互式编辑器-JupyterNotebook.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        交互式编辑器-JupyterNotebook
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="python数据分析环境和工具/5.1Jupyter-notebook拓展应用.html">
            
                
                    <a href="../python数据分析环境和工具/5.1Jupyter-notebook拓展应用.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.1.</b>
                        
                        Jupyter-notebook拓展应用
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="python数据分析环境和工具/包和环境管理器：conda.html">
            
                
                    <a href="../python数据分析环境和工具/包和环境管理器：conda.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        包和环境管理器：conda
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="python数据分析环境和工具/pip和Virtualenv.html">
            
                
                    <a href="../python数据分析环境和工具/pip和Virtualenv.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.1.</b>
                        
                        pip和Virtualenv
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="python数据分析环境和工具/3Markdown.html">
            
                
                    <a href="../python数据分析环境和工具/3Markdown.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        标记语言：Markdown
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.5.1" data-path="python数据分析环境和工具/4Markdown语法.html">
            
                
                    <a href="../python数据分析环境和工具/4Markdown语法.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.1.</b>
                        
                        Markdown语法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5.2" data-path="python数据分析环境和工具/6Gitbook文档.html">
            
                
                    <a href="../python数据分析环境和工具/6Gitbook文档.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.2.</b>
                        
                        文档管理工具-Gitbook
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="数据分析库的初步认识/index.html">
            
                
                    <a href="../数据分析库的初步认识/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        数据分析库-Pandas
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="数据分析库的初步认识/Pandas创建.html">
            
                
                    <a href="../数据分析库的初步认识/Pandas创建.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        pandas
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="数据分析库的初步认识/Series创建.html">
            
                
                    <a href="../数据分析库的初步认识/Series创建.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        Series
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="数据分析库的初步认识/DataFrame创建.html">
            
                
                    <a href="../数据分析库的初步认识/DataFrame创建.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        DataFrame对象-创建
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" >
            
            <span><b>4.</b> 数据分析库的操作</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="数据分析库的操作/1DataFrame查询1-整体.html">
            
                
                    <a href="../数据分析库的操作/1DataFrame查询1-整体.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        DataFrame查询1-整体
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="数据分析库的操作/2DataFrame查询2-专用查询.html">
            
                
                    <a href="../数据分析库的操作/2DataFrame查询2-专用查询.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        DataFrame查询2-专用查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="数据分析库的操作/3DataFrame查询3-专有查询：过滤查询.html">
            
                
                    <a href="../数据分析库的操作/3DataFrame查询3-专有查询：过滤查询.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        DataFrame查询3-专有查询：过滤查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="数据分析库的操作/4Pandas对象的数据操作：增删改查.html">
            
                
                    <a href="../数据分析库的操作/4Pandas对象的数据操作：增删改查.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        Pandas对象的数据操作：增删改查
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.4.1" data-path="数据分析库的操作/5Pandas数据操作：其他操作.html">
            
                
                    <a href="../数据分析库的操作/5Pandas数据操作：其他操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.1.</b>
                        
                        Pandas数据操作：其他操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4.2" data-path="数据分析库的操作/6Pandas数据存取.html">
            
                
                    <a href="../数据分析库的操作/6Pandas数据存取.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.2.</b>
                        
                        Pandas数据存取
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4.3" data-path="数据分析库的操作/7Pandas数据运算.html">
            
                
                    <a href="../数据分析库的操作/7Pandas数据运算.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.3.</b>
                        
                        Pandas数据运算
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.4.3.1" data-path="数据分析库的操作/7.1Pandas数据运算拓展.html">
            
                
                    <a href="../数据分析库的操作/7.1Pandas数据运算拓展.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.3.1.</b>
                        
                        Pandas数据运算-拓展
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.4.4" data-path="数据分析库的操作/8Pandas分组聚合1.html">
            
                
                    <a href="../数据分析库的操作/8Pandas分组聚合1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.4.</b>
                        
                        Pandas分组聚合1
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4.5" data-path="数据分析库的操作/9Pandas分组聚合2.html">
            
                
                    <a href="../数据分析库的操作/9Pandas分组聚合2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.5.</b>
                        
                        Pandas分组聚合2
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4.6" data-path="数据分析库的操作/10Pandas数据规整-清理.html">
            
                
                    <a href="../数据分析库的操作/10Pandas数据规整-清理.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.6.</b>
                        
                        Pandas数据规整-清理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4.7" data-path="数据分析库的操作/11Pandas数据规整-转换.html">
            
                
                    <a href="../数据分析库的操作/11Pandas数据规整-转换.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.7.</b>
                        
                        Pandas数据规整-转换
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.4.7.1" data-path="数据分析库的操作/14Pandas数据规整-转换-离散化和面元划分.html">
            
                
                    <a href="../数据分析库的操作/14Pandas数据规整-转换-离散化和面元划分.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.7.1.</b>
                        
                        离散化和面元划分
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter active" data-level="4.4.8" data-path="数据分析库的操作/16Pandas数据规整-合并.html">
            
                
                    <a href="../数据分析库的操作/16Pandas数据规整-合并.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.8.</b>
                        
                        Pandas数据规整-合并
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="数据分析库的操作/13Pandas数据规整-重塑和轴向旋转.html">
            
                
                    <a href="../数据分析库的操作/13Pandas数据规整-重塑和轴向旋转.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        Pandas数据规整-重塑和轴向旋转
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.5.1" data-path="数据分析库的操作/13.1透视表和交叉表.html">
            
                
                    <a href="../数据分析库的操作/13.1透视表和交叉表.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.1.</b>
                        
                        透视表和交叉表
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="Python可视化/绘图库-Matplotlib.html">
            
                
                    <a href="../Python可视化/绘图库-Matplotlib.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        Python可视化
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="Python可视化/绘图库-Matplotlib/Matplotlib常见图表.html">
            
                
                    <a href="../Python可视化/绘图库-Matplotlib/Matplotlib常见图表.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        基础：Matplotlib常见图表
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.1" data-path="Python可视化/绘图库-Matplotlib/Matplotlib常见设置和操作.html">
            
                
                    <a href="../Python可视化/绘图库-Matplotlib/Matplotlib常见设置和操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.1.</b>
                        
                        Matplotlib常见设置和操作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="Python可视化/绘图库-Matplotlib/1Matplotlib-绘图区域.html">
            
                
                    <a href="../Python可视化/绘图库-Matplotlib/1Matplotlib-绘图区域.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        提升：绘图区域
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="Python可视化/绘图库-Matplotlib/2Matplotlib-图像组件.html">
            
                
                    <a href="../Python可视化/绘图库-Matplotlib/2Matplotlib-图像组件.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        提升：绘图组件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="Python可视化/绘图库-Matplotlib/3Matplotlib-高级绘图.html">
            
                
                    <a href="../Python可视化/绘图库-Matplotlib/3Matplotlib-高级绘图.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        拓展：高级绘图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="Python可视化/绘图库-Matplotlib/4数学计算展示图像.html">
            
                
                    <a href="../Python可视化/绘图库-Matplotlib/4数学计算展示图像.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        拓展：数学计算展示图像
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="Python可视化/绘图库-Matplotlib/5注意事项.html">
            
                
                    <a href="../Python可视化/绘图库-Matplotlib/5注意事项.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        拓展：注意事项
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="Python可视化/绘图库-Matplotlib/6pylab.html">
            
                
                    <a href="../Python可视化/绘图库-Matplotlib/6pylab.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        拓展：pylab
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="数据分析必备知识点/数据分析必备知识点汇集.html">
            
                
                    <a href="../数据分析必备知识点/数据分析必备知识点汇集.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        数据分析必备知识点
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7" data-path="数据分析必备知识点/数据分析流程.html">
            
                
                    <a href="../数据分析必备知识点/数据分析流程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        数据分析流程
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >Python 数据分析学习目录</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="pandas&#x6570;&#x636E;&#x89C4;&#x6574;&#x5408;&#x5E76;">Pandas&#x6570;&#x636E;&#x89C4;&#x6574;-&#x5408;&#x5E76;</h1>
<p>&#x6570;&#x636E;&#x5408;&#x5E76;</p>
<p>Pandas&#x63D0;&#x4F9B;&#x4E86;&#x5927;&#x91CF;&#x65B9;&#x6CD5;&#xFF0C;&#x80FD;&#x8F7B;&#x677E;&#x7684;&#x5BF9;Series&#xFF0C;DataFrame&#x6267;&#x884C;&#x5408;&#x5E76;&#x64CD;&#x4F5C;</p>
<ul>
<li><p>&#x8FFD;&#x52A0; .append()</p>
</li>
<li><p>&#x7B80;&#x5355;&#x5408;&#x5E76; .concat()  concat()&#x5408;&#x5E76;&#x7684;&#x524D;&#x63D0;&#x662F;&#x7D22;&#x5F15;&#x4E00;&#x81F4;</p>
</li>
<li><p>&#x590D;&#x6742;&#x5408;&#x5E76; .merge()&#x548C;.join()</p>
<ul>
<li>merge()&#x51FD;&#x6570;&#x7528;&#x4E8E;&#x590D;&#x6742;&#x7EFC;&#x5408;&#x6570;&#x636E;&#x5408;&#x5E76;,&#x64CD;&#x4F5C;&#x590D;&#x6742;&#xFF0C;&#x529F;&#x80FD;&#x5F3A;&#x5927;</li>
<li>&#x6309;&#x884C;&#x7D22;&#x5F15;&#x5408;&#x5E76; join()&#x51FD;&#x6570;&#x7528;&#x4E8E;&#x6309;&#x7D22;&#x5F15;&#x5408;&#x5E76;&#xFF0C;&#x64CD;&#x4F5C;&#x7B80;&#x5355;&#xFF0C;&#x529F;&#x80FD;&#x5355;&#x4E00;</li>
</ul>
</li>
<li>&#x5408;&#x5E76;&#x91CD;&#x53E0;&#x6570;&#x636E;&#xFF08;&#x4E00;&#x4E2A;&#x8868;&#x4E3A;&#x4E3B;&#xFF0C;&#x5148;&#x586B;&#x5145;&#x518D;&#x5408;&#x5E76;&#xFF09;&#xFF1A;combine_first</li>
</ul>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd
</code></pre>
<h1 id="&#x8FFD;&#x52A0;-append">&#x8FFD;&#x52A0; append()</h1>
<pre><code class="lang-python">df = pd.DataFrame(np.random.randn(<span class="hljs-number">8</span>, <span class="hljs-number">4</span>), columns = [<span class="hljs-string">&apos;A&apos;</span>,<span class="hljs-string">&apos;B&apos;</span>,<span class="hljs-string">&apos;C&apos;</span>,<span class="hljs-string">&apos;D&apos;</span>])
df
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>A</th>
      <th>B</th>
      <th>C</th>
      <th>D</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0.608713</td>
      <td>1.133601</td>
      <td>-0.387001</td>
      <td>-0.833521</td>
    </tr>
    <tr>
      <th>1</th>
      <td>-1.665263</td>
      <td>0.292946</td>
      <td>-1.419200</td>
      <td>-1.897477</td>
    </tr>
    <tr>
      <th>2</th>
      <td>1.054422</td>
      <td>1.080865</td>
      <td>1.021990</td>
      <td>1.498744</td>
    </tr>
    <tr>
      <th>3</th>
      <td>1.998903</td>
      <td>0.066551</td>
      <td>0.137134</td>
      <td>0.760518</td>
    </tr>
    <tr>
      <th>4</th>
      <td>-1.485375</td>
      <td>0.407789</td>
      <td>0.503487</td>
      <td>0.382787</td>
    </tr>
    <tr>
      <th>5</th>
      <td>1.386431</td>
      <td>-0.674478</td>
      <td>-2.071466</td>
      <td>-0.500711</td>
    </tr>
    <tr>
      <th>6</th>
      <td>2.199215</td>
      <td>-1.487788</td>
      <td>1.893095</td>
      <td>-0.214528</td>
    </tr>
    <tr>
      <th>7</th>
      <td>-0.584068</td>
      <td>0.956783</td>
      <td>-0.566554</td>
      <td>-0.179507</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python">s = df.loc[[<span class="hljs-number">3</span>, <span class="hljs-number">5</span>]]
s
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>A</th>
      <th>B</th>
      <th>C</th>
      <th>D</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>3</th>
      <td>1.998903</td>
      <td>0.066551</td>
      <td>0.137134</td>
      <td>0.760518</td>
    </tr>
    <tr>
      <th>5</th>
      <td>1.386431</td>
      <td>-0.674478</td>
      <td>-2.071466</td>
      <td>-0.500711</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python"><span class="hljs-comment">#&#x8FFD;&#x52A0;&#x5408;&#x5E76;</span>

df.append(s)
df.append(s, ignore_index = <span class="hljs-keyword">True</span>)   <span class="hljs-comment">#&#x4E0D;&#x4F7F;&#x7528;&#x8FFD;&#x52A0;&#x8868;&#x7684;&#x7D22;&#x5F15;</span>
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>A</th>
      <th>B</th>
      <th>C</th>
      <th>D</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0.608713</td>
      <td>1.133601</td>
      <td>-0.387001</td>
      <td>-0.833521</td>
    </tr>
    <tr>
      <th>1</th>
      <td>-1.665263</td>
      <td>0.292946</td>
      <td>-1.419200</td>
      <td>-1.897477</td>
    </tr>
    <tr>
      <th>2</th>
      <td>1.054422</td>
      <td>1.080865</td>
      <td>1.021990</td>
      <td>1.498744</td>
    </tr>
    <tr>
      <th>3</th>
      <td>1.998903</td>
      <td>0.066551</td>
      <td>0.137134</td>
      <td>0.760518</td>
    </tr>
    <tr>
      <th>4</th>
      <td>-1.485375</td>
      <td>0.407789</td>
      <td>0.503487</td>
      <td>0.382787</td>
    </tr>
    <tr>
      <th>5</th>
      <td>1.386431</td>
      <td>-0.674478</td>
      <td>-2.071466</td>
      <td>-0.500711</td>
    </tr>
    <tr>
      <th>6</th>
      <td>2.199215</td>
      <td>-1.487788</td>
      <td>1.893095</td>
      <td>-0.214528</td>
    </tr>
    <tr>
      <th>7</th>
      <td>-0.584068</td>
      <td>0.956783</td>
      <td>-0.566554</td>
      <td>-0.179507</td>
    </tr>
    <tr>
      <th>8</th>
      <td>1.998903</td>
      <td>0.066551</td>
      <td>0.137134</td>
      <td>0.760518</td>
    </tr>
    <tr>
      <th>9</th>
      <td>1.386431</td>
      <td>-0.674478</td>
      <td>-2.071466</td>
      <td>-0.500711</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python">df.append(s, ignore_index = <span class="hljs-keyword">True</span>)   <span class="hljs-comment">#&#x4E0D;&#x4F7F;&#x7528;&#x8FFD;&#x52A0;&#x8868;&#x7684;&#x7D22;&#x5F15;</span>
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>A</th>
      <th>B</th>
      <th>C</th>
      <th>D</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0.608713</td>
      <td>1.133601</td>
      <td>-0.387001</td>
      <td>-0.833521</td>
    </tr>
    <tr>
      <th>1</th>
      <td>-1.665263</td>
      <td>0.292946</td>
      <td>-1.419200</td>
      <td>-1.897477</td>
    </tr>
    <tr>
      <th>2</th>
      <td>1.054422</td>
      <td>1.080865</td>
      <td>1.021990</td>
      <td>1.498744</td>
    </tr>
    <tr>
      <th>3</th>
      <td>1.998903</td>
      <td>0.066551</td>
      <td>0.137134</td>
      <td>0.760518</td>
    </tr>
    <tr>
      <th>4</th>
      <td>-1.485375</td>
      <td>0.407789</td>
      <td>0.503487</td>
      <td>0.382787</td>
    </tr>
    <tr>
      <th>5</th>
      <td>1.386431</td>
      <td>-0.674478</td>
      <td>-2.071466</td>
      <td>-0.500711</td>
    </tr>
    <tr>
      <th>6</th>
      <td>2.199215</td>
      <td>-1.487788</td>
      <td>1.893095</td>
      <td>-0.214528</td>
    </tr>
    <tr>
      <th>7</th>
      <td>-0.584068</td>
      <td>0.956783</td>
      <td>-0.566554</td>
      <td>-0.179507</td>
    </tr>
    <tr>
      <th>8</th>
      <td>1.998903</td>
      <td>0.066551</td>
      <td>0.137134</td>
      <td>0.760518</td>
    </tr>
    <tr>
      <th>9</th>
      <td>1.386431</td>
      <td>-0.674478</td>
      <td>-2.071466</td>
      <td>-0.500711</td>
    </tr>
  </tbody>
</table>
</div>



<h3 id="dataframe&#x548C;series&#x8FFD;&#x52A0;&#x5408;&#x5E76;">DataFrame&#x548C;Series&#x8FFD;&#x52A0;&#x5408;&#x5E76;</h3>
<pre><code class="lang-python">s2 = pd.Series([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>], index = [<span class="hljs-string">&apos;A&apos;</span>,<span class="hljs-string">&apos;B&apos;</span>,<span class="hljs-string">&apos;C&apos;</span>,<span class="hljs-string">&apos;D&apos;</span>])
s2
</code></pre>
<pre><code>A    1
B    2
C    3
D    4
dtype: int64
</code></pre><pre><code class="lang-python">df.append(s2, ignore_index=<span class="hljs-keyword">True</span>)
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>A</th>
      <th>B</th>
      <th>C</th>
      <th>D</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0.608713</td>
      <td>1.133601</td>
      <td>-0.387001</td>
      <td>-0.833521</td>
    </tr>
    <tr>
      <th>1</th>
      <td>-1.665263</td>
      <td>0.292946</td>
      <td>-1.419200</td>
      <td>-1.897477</td>
    </tr>
    <tr>
      <th>2</th>
      <td>1.054422</td>
      <td>1.080865</td>
      <td>1.021990</td>
      <td>1.498744</td>
    </tr>
    <tr>
      <th>3</th>
      <td>1.998903</td>
      <td>0.066551</td>
      <td>0.137134</td>
      <td>0.760518</td>
    </tr>
    <tr>
      <th>4</th>
      <td>-1.485375</td>
      <td>0.407789</td>
      <td>0.503487</td>
      <td>0.382787</td>
    </tr>
    <tr>
      <th>5</th>
      <td>1.386431</td>
      <td>-0.674478</td>
      <td>-2.071466</td>
      <td>-0.500711</td>
    </tr>
    <tr>
      <th>6</th>
      <td>2.199215</td>
      <td>-1.487788</td>
      <td>1.893095</td>
      <td>-0.214528</td>
    </tr>
    <tr>
      <th>7</th>
      <td>-0.584068</td>
      <td>0.956783</td>
      <td>-0.566554</td>
      <td>-0.179507</td>
    </tr>
    <tr>
      <th>8</th>
      <td>1.000000</td>
      <td>2.000000</td>
      <td>3.000000</td>
      <td>4.000000</td>
    </tr>
  </tbody>
</table>
</div>



<h1 id="&#x8FDE;&#x63A5;-concat">&#x8FDE;&#x63A5; .concat()</h1>
<pre><code class="lang-python">df = pd.DataFrame(np.random.randn(<span class="hljs-number">10</span>, <span class="hljs-number">4</span>))
df
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>0</th>
      <th>1</th>
      <th>2</th>
      <th>3</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0.292558</td>
      <td>1.093953</td>
      <td>0.002249</td>
      <td>0.021471</td>
    </tr>
    <tr>
      <th>1</th>
      <td>-1.469323</td>
      <td>1.457726</td>
      <td>1.608742</td>
      <td>0.106506</td>
    </tr>
    <tr>
      <th>2</th>
      <td>-1.145514</td>
      <td>0.160136</td>
      <td>1.569160</td>
      <td>1.614615</td>
    </tr>
    <tr>
      <th>3</th>
      <td>-1.790061</td>
      <td>-0.340697</td>
      <td>-0.366011</td>
      <td>-0.432241</td>
    </tr>
    <tr>
      <th>4</th>
      <td>-1.018275</td>
      <td>1.590433</td>
      <td>2.062223</td>
      <td>2.190167</td>
    </tr>
    <tr>
      <th>5</th>
      <td>-0.628959</td>
      <td>-0.875532</td>
      <td>0.326061</td>
      <td>-0.368389</td>
    </tr>
    <tr>
      <th>6</th>
      <td>0.692785</td>
      <td>0.044703</td>
      <td>0.027657</td>
      <td>-0.095128</td>
    </tr>
    <tr>
      <th>7</th>
      <td>-1.019091</td>
      <td>-1.435424</td>
      <td>-1.283300</td>
      <td>0.541989</td>
    </tr>
    <tr>
      <th>8</th>
      <td>-0.159100</td>
      <td>0.300605</td>
      <td>-0.332208</td>
      <td>-0.625929</td>
    </tr>
    <tr>
      <th>9</th>
      <td>0.805078</td>
      <td>-0.431684</td>
      <td>1.999406</td>
      <td>-0.264300</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python">x = df.loc[:<span class="hljs-number">2</span>]
x

y = df.loc[<span class="hljs-number">4</span>:<span class="hljs-number">6</span>]
y

z = df[-<span class="hljs-number">2</span>:]
z
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>0</th>
      <th>1</th>
      <th>2</th>
      <th>3</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>8</th>
      <td>-0.159100</td>
      <td>0.300605</td>
      <td>-0.332208</td>
      <td>-0.625929</td>
    </tr>
    <tr>
      <th>9</th>
      <td>0.805078</td>
      <td>-0.431684</td>
      <td>1.999406</td>
      <td>-0.264300</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python">pd.concat([x,y,z])   <span class="hljs-comment">#&#x5C06;&#x5408;&#x5E76;&#x8868;&#x683C;&#x653E;&#x5165;&#x5217;&#x8868;</span>
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>0</th>
      <th>1</th>
      <th>2</th>
      <th>3</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0.292558</td>
      <td>1.093953</td>
      <td>0.002249</td>
      <td>0.021471</td>
    </tr>
    <tr>
      <th>1</th>
      <td>-1.469323</td>
      <td>1.457726</td>
      <td>1.608742</td>
      <td>0.106506</td>
    </tr>
    <tr>
      <th>2</th>
      <td>-1.145514</td>
      <td>0.160136</td>
      <td>1.569160</td>
      <td>1.614615</td>
    </tr>
    <tr>
      <th>4</th>
      <td>-1.018275</td>
      <td>1.590433</td>
      <td>2.062223</td>
      <td>2.190167</td>
    </tr>
    <tr>
      <th>5</th>
      <td>-0.628959</td>
      <td>-0.875532</td>
      <td>0.326061</td>
      <td>-0.368389</td>
    </tr>
    <tr>
      <th>6</th>
      <td>0.692785</td>
      <td>0.044703</td>
      <td>0.027657</td>
      <td>-0.095128</td>
    </tr>
    <tr>
      <th>8</th>
      <td>-0.159100</td>
      <td>0.300605</td>
      <td>-0.332208</td>
      <td>-0.625929</td>
    </tr>
    <tr>
      <th>9</th>
      <td>0.805078</td>
      <td>-0.431684</td>
      <td>1.999406</td>
      <td>-0.264300</td>
    </tr>
  </tbody>
</table>
</div>



<h1 id="&#x590D;&#x6742;&#x5408;&#x5E76;-merge&#x548C;join">&#x590D;&#x6742;&#x5408;&#x5E76; .merge()&#x548C;.join()</h1>
<p>merge()&#x51FD;&#x6570;&#x7528;&#x4E8E;&#x590D;&#x6742;&#x7EFC;&#x5408;&#x6570;&#x636E;&#x5408;&#x5E76;,&#x64CD;&#x4F5C;&#x590D;&#x6742;&#xFF0C;&#x529F;&#x80FD;&#x5F3A;&#x5927;</p>
<p>join()&#x662F;merge()&#x7684;&#x4E00;&#x4E2A;&#x7279;&#x6B8A;&#x7528;&#x6CD5;&#xFF0C;&#x7528;&#x4E8E;&#x6309;&#x7D22;&#x5F15;&#x5408;&#x5E76;&#xFF0C;&#x64CD;&#x4F5C;&#x7B80;&#x5355;&#xFF0C;&#x529F;&#x80FD;&#x5355;&#x4E00;</p>
<pre><code class="lang-python"><span class="hljs-comment"># df1&#xFF0C;&#x59D3;&#x540D;&#x548C;&#x5206;&#x7EC4;</span>
df1 = pd.DataFrame({
    <span class="hljs-string">&apos;name&apos;</span>: [<span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>, <span class="hljs-string">&apos;&#x674E;&#x56DB;&apos;</span>, <span class="hljs-string">&apos;&#x738B;&#x4E94;&apos;</span>, <span class="hljs-string">&apos;&#x8D75;&#x516D;&apos;</span>],
    <span class="hljs-string">&apos;group&apos;</span>: [<span class="hljs-string">&apos;DBA&apos;</span>, <span class="hljs-string">&apos;PM&apos;</span>,<span class="hljs-string">&apos;PM&apos;</span>, <span class="hljs-string">&apos;HR&apos;</span>]
})
df1
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>group</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>DBA</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x674E;&#x56DB;</td>
      <td>PM</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x738B;&#x4E94;</td>
      <td>PM</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x8D75;&#x516D;</td>
      <td>HR</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python"><span class="hljs-comment"># df2&#xFF0C;&#x59D3;&#x540D;&#x548C;&#x5165;&#x804C;&#x65F6;&#x95F4;</span>
df2 = pd.DataFrame({
    <span class="hljs-string">&apos;name&apos;</span>: [<span class="hljs-string">&apos;&#x674E;&#x56DB;&apos;</span>, <span class="hljs-string">&apos;&#x8D75;&#x516D;&apos;</span>, <span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>, <span class="hljs-string">&apos;&#x738B;&#x4E94;&apos;</span>],
    <span class="hljs-string">&apos;date&apos;</span>: [<span class="hljs-number">2004</span>, <span class="hljs-number">2008</span>, <span class="hljs-number">2012</span>, <span class="hljs-number">2014</span>]
})
df2
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>date</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x674E;&#x56DB;</td>
      <td>2004</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x8D75;&#x516D;</td>
      <td>2008</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>2012</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x738B;&#x4E94;</td>
      <td>2014</td>
    </tr>
  </tbody>
</table>
</div>



<p>&#x4E24;&#x4E2A;&#x8868;&#x5FC5;&#x987B;&#x6709;&#x76F8;&#x5173;&#x6027;&#xFF0C;&#x624D;&#x6709;&#x5408;&#x5E76;&#x7684;&#x9700;&#x8981;</p>
<p>&#x4EE5;&#x76F8;&#x540C;&#x7684;&#x5217;&#x7D22;&#x5F15;&#x4E3A;&#x57FA;&#x51C6;&#xFF0C;&#x5408;&#x5E76;</p>
<p>&#x5408;&#x5E76;&#x4E24;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x9ED8;&#x8BA4;&#x5339;&#x914D;&#x76F8;&#x540C;&#x8FC7;&#x7684;&#x5217;&#x540D;&#xFF0C;&#x81EA;&#x52A8;&#x5BF9;&#x9F50;&#x5408;&#x5E76;</p>
<pre><code class="lang-python">df3 = pd.merge(df1, df2)
df3
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>group</th>
      <th>date</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>DBA</td>
      <td>2012</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x674E;&#x56DB;</td>
      <td>PM</td>
      <td>2004</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x738B;&#x4E94;</td>
      <td>PM</td>
      <td>2014</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x8D75;&#x516D;</td>
      <td>HR</td>
      <td>2008</td>
    </tr>
  </tbody>
</table>
</div>



<p>&#x8981;&#x5408;&#x5E76;&#x7684;&#x6837;&#x672C;&#x91CF;&#xFF08;&#x884C;&#x6570;&#xFF09;&#x4E0D;&#x540C;&#x65F6;&#xFF0C;&#x5408;&#x5E76;&#x540E;&#x7684;&#x6570;&#x636E;&#x4F1A;&#x81EA;&#x52A8;&#x6269;&#x5C55;&#xFF0C;&#x4E0D;&#x635F;&#x5931;&#x4FE1;&#x606F;</p>
<pre><code class="lang-python">df3
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>group</th>
      <th>date</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>DBA</td>
      <td>2012</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x674E;&#x56DB;</td>
      <td>PM</td>
      <td>2004</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x738B;&#x4E94;</td>
      <td>PM</td>
      <td>2014</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x8D75;&#x516D;</td>
      <td>HR</td>
      <td>2008</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python"><span class="hljs-comment"># df4&#xFF0C;&#x6BCF;&#x4E2A;&#x5206;&#x7EC4;&#x7684;&#x9886;&#x5BFC;&#xFF0C;&#x884C;&#x6570;&#x5C11;</span>
df4 = pd.DataFrame({
    <span class="hljs-string">&apos;group&apos;</span>: [<span class="hljs-string">&apos;DBA&apos;</span>, <span class="hljs-string">&apos;PM&apos;</span>, <span class="hljs-string">&apos;HR&apos;</span>],
    <span class="hljs-string">&apos;leader&apos;</span>: [<span class="hljs-string">&apos;&#x94B1;&#x5927;&apos;</span>, <span class="hljs-string">&apos;&#x5B59;&#x4E8C;&apos;</span>, <span class="hljs-string">&apos;&#x5468;&#x4E09;&apos;</span>]
})
df4
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>group</th>
      <th>leader</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>DBA</td>
      <td>&#x94B1;&#x5927;</td>
    </tr>
    <tr>
      <th>1</th>
      <td>PM</td>
      <td>&#x5B59;&#x4E8C;</td>
    </tr>
    <tr>
      <th>2</th>
      <td>HR</td>
      <td>&#x5468;&#x4E09;</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python"><span class="hljs-comment"># &#x6837;&#x672C;&#x91CF;&#xFF08;&#x884C;&#x6570;&#xFF09;&#x4E0D;&#x540C;&#x65F6;&#xFF0C;&#x5408;&#x5E76;&#x540E;&#x7684;&#x6570;&#x636E;&#x4F1A;&#x81EA;&#x52A8;&#x6269;&#x5C55;&#xFF0C;&#x4E0D;&#x635F;&#x5931;&#x4FE1;&#x606F;</span>
pd.merge(df3, df4)
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>group</th>
      <th>date</th>
      <th>leader</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>DBA</td>
      <td>2012</td>
      <td>&#x94B1;&#x5927;</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x674E;&#x56DB;</td>
      <td>PM</td>
      <td>2004</td>
      <td>&#x5B59;&#x4E8C;</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x738B;&#x4E94;</td>
      <td>PM</td>
      <td>2014</td>
      <td>&#x5B59;&#x4E8C;</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x8D75;&#x516D;</td>
      <td>HR</td>
      <td>2008</td>
      <td>&#x5468;&#x4E09;</td>
    </tr>
  </tbody>
</table>
</div>



<p>&#x5206;&#x7EC4;&#x548C;&#x6280;&#x80FD;&#xFF0C;&#x884C;&#x6570;&#x591A;</p>
<pre><code class="lang-python">df1
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>group</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>DBA</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x674E;&#x56DB;</td>
      <td>PM</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x738B;&#x4E94;</td>
      <td>PM</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x8D75;&#x516D;</td>
      <td>HR</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python">df5 = pd.DataFrame({
    <span class="hljs-string">&apos;group&apos;</span>: [<span class="hljs-string">&apos;DBA&apos;</span>, <span class="hljs-string">&apos;DBA&apos;</span>,<span class="hljs-string">&apos;PM&apos;</span>, <span class="hljs-string">&apos;PM&apos;</span>, <span class="hljs-string">&apos;HR&apos;</span>, <span class="hljs-string">&apos;HR&apos;</span>],
    <span class="hljs-string">&apos;skills&apos;</span>: [<span class="hljs-string">&apos;Linux&apos;</span>, <span class="hljs-string">&apos;&#x6570;&#x636E;&#x5E93;&apos;</span>, <span class="hljs-string">&apos;Axuer RP&apos;</span>, <span class="hljs-string">&apos;&#x793E;&#x4EA4;&apos;</span>,<span class="hljs-string">&apos;&#x62DB;&#x8058;&apos;</span>, <span class="hljs-string">&apos;&#x7EC4;&#x7EC7;&apos;</span>]
})
df5
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>group</th>
      <th>skills</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>DBA</td>
      <td>Linux</td>
    </tr>
    <tr>
      <th>1</th>
      <td>DBA</td>
      <td>&#x6570;&#x636E;&#x5E93;</td>
    </tr>
    <tr>
      <th>2</th>
      <td>PM</td>
      <td>Axuer RP</td>
    </tr>
    <tr>
      <th>3</th>
      <td>PM</td>
      <td>&#x793E;&#x4EA4;</td>
    </tr>
    <tr>
      <th>4</th>
      <td>HR</td>
      <td>&#x62DB;&#x8058;</td>
    </tr>
    <tr>
      <th>5</th>
      <td>HR</td>
      <td>&#x7EC4;&#x7EC7;</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python">pd.merge(df1, df5)
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>group</th>
      <th>skills</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>DBA</td>
      <td>Linux</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>DBA</td>
      <td>&#x6570;&#x636E;&#x5E93;</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x674E;&#x56DB;</td>
      <td>PM</td>
      <td>Axuer RP</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x674E;&#x56DB;</td>
      <td>PM</td>
      <td>&#x793E;&#x4EA4;</td>
    </tr>
    <tr>
      <th>4</th>
      <td>&#x738B;&#x4E94;</td>
      <td>PM</td>
      <td>Axuer RP</td>
    </tr>
    <tr>
      <th>5</th>
      <td>&#x738B;&#x4E94;</td>
      <td>PM</td>
      <td>&#x793E;&#x4EA4;</td>
    </tr>
    <tr>
      <th>6</th>
      <td>&#x8D75;&#x516D;</td>
      <td>HR</td>
      <td>&#x62DB;&#x8058;</td>
    </tr>
    <tr>
      <th>7</th>
      <td>&#x8D75;&#x516D;</td>
      <td>HR</td>
      <td>&#x7EC4;&#x7EC7;</td>
    </tr>
  </tbody>
</table>
</div>



<h1 id="&#x4E24;&#x4E2A;&#x8868;&#x6CA1;&#x6709;&#x540C;&#x540D;&#x5217;&#x65F6;&#xFF0C;&#x5982;&#x4F55;&#x5408;&#x5E76;">&#x4E24;&#x4E2A;&#x8868;&#x6CA1;&#x6709;&#x540C;&#x540D;&#x5217;&#x65F6;&#xFF0C;&#x5982;&#x4F55;&#x5408;&#x5E76;</h1>
<p>&#x4E24;&#x4E2A;&#x5BF9;&#x8C61;&#x6CA1;&#x6709;&#x540C;&#x540D;&#x5217;&#x65F6;&#xFF0C;&#x7528;left_on&#x548C;right_on&#x5F3A;&#x5236;&#x6307;&#x5B9A;&#x5217;&#x540D;&#x5BF9;&#x5E94;&#x5408;&#x5E76;</p>
<pre><code class="lang-python"><span class="hljs-comment"># df1&#xFF0C;&#x59D3;&#x540D; name &#x548C;&#x5206;&#x7EC4;</span>
df1
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>group</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>DBA</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x674E;&#x56DB;</td>
      <td>PM</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x738B;&#x4E94;</td>
      <td>PM</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x8D75;&#x516D;</td>
      <td>HR</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python"><span class="hljs-comment"># df6&#xFF0C;&#x59D3;&#x540D;2 username &#x548C;&#x85AA;&#x8D44;</span>
df6 = pd.DataFrame({
    <span class="hljs-string">&apos;username&apos;</span>: [<span class="hljs-string">&apos;&#x738B;&#x4E94;&apos;</span>, <span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>, <span class="hljs-string">&apos;&#x8D75;&#x516D;&apos;</span>, <span class="hljs-string">&apos;&#x674E;&#x56DB;&apos;</span>],
    <span class="hljs-string">&apos;salary&apos;</span>: [<span class="hljs-number">10000</span>, <span class="hljs-number">160000</span>, <span class="hljs-number">7000</span>, <span class="hljs-number">120000</span>]
})
df6
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>username</th>
      <th>salary</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x738B;&#x4E94;</td>
      <td>10000</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>160000</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x8D75;&#x516D;</td>
      <td>7000</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x674E;&#x56DB;</td>
      <td>120000</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python">pd.merge(df1, df6, left_on=<span class="hljs-string">&apos;name&apos;</span>, right_on=<span class="hljs-string">&apos;username&apos;</span>)
pd.merge(df1, df6, left_on=<span class="hljs-string">&apos;name&apos;</span>, right_on=<span class="hljs-string">&apos;username&apos;</span>).drop(<span class="hljs-string">&apos;username&apos;</span>, axis=<span class="hljs-number">1</span>)
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>group</th>
      <th>salary</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>DBA</td>
      <td>160000</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x674E;&#x56DB;</td>
      <td>PM</td>
      <td>120000</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x738B;&#x4E94;</td>
      <td>PM</td>
      <td>10000</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x8D75;&#x516D;</td>
      <td>HR</td>
      <td>7000</td>
    </tr>
  </tbody>
</table>
</div>



<h1 id="&#x6309;&#x7167;&#x884C;&#x7D22;&#x5F15;&#x5408;&#x5E76;">&#x6309;&#x7167;&#x884C;&#x7D22;&#x5F15;&#x5408;&#x5E76;</h1>
<p>&#x5F53;&#x8981;&#x5408;&#x5E76;&#x6570;&#x636E;&#x7684;&#x884C;&#x7D22;&#x5F15;&#x76F8;&#x5173;&#x65F6;&#xFF0C;&#x6307;&#x5B9A; merge() &#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570; left_index &#x4E0E; right_index &#x7684;&#x503C;&#x4E3A; True&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x81EA;&#x52A8;&#x4F9D;&#x7167;&#x7D22;&#x5F15;&#x5E8F;&#x53F7;&#x5408;&#x5E76;</p>
<p>join()&#x51FD;&#x6570;&#x4E5F;&#x80FD;&#x5B9E;&#x73B0;&#xFF0C;&#x5199;&#x6CD5;&#x66F4;&#x7B80;&#x5355;</p>
<p>merge()&#x7684;&#x4F18;&#x52BF;&#x5728;&#x4E8E;&#x66F4;&#x7075;&#x6D3B;&#xFF0C;&#x5C24;&#x5176;&#x662F;&#x5F53;&#x6570;&#x636E;&#x96C6;&#x7D22;&#x5F15;&#x503C;&#x5DEE;&#x522B;&#x5F88;&#x5927;&#xFF0C;&#x6570;&#x636E;&#x5408;&#x5E76;&#x53C8;&#x5FC5;&#x987B;&#x4EE5;&#x5176;&#x4E2D;&#x4E00;&#x7EC4;&#x6570;&#x636E;&#x7684;&#x7D22;&#x5F15;&#x503C;&#x4E3A;&#x4F9D;&#x636E;&#x65F6;</p>
<pre><code class="lang-python"><span class="hljs-comment"># df1a&#xFF0C;&#x5C06;df1&#x7684;name&#x5217;&#x8BBE;&#x4E3A;&#x884C;&#x7D22;&#x5F15;</span>
df1a = df1.set_index(<span class="hljs-string">&apos;name&apos;</span>)
df1a
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>group</th>
    </tr>
    <tr>
      <th>name</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>&#x5F20;&#x4E09;</th>
      <td>DBA</td>
    </tr>
    <tr>
      <th>&#x674E;&#x56DB;</th>
      <td>PM</td>
    </tr>
    <tr>
      <th>&#x738B;&#x4E94;</th>
      <td>PM</td>
    </tr>
    <tr>
      <th>&#x8D75;&#x516D;</th>
      <td>HR</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python"><span class="hljs-comment"># df2a&#xFF0C;&#x5C06;df2&#x7684;name&#x5217;&#x8BBE;&#x4E3A;&#x884C;&#x7D22;&#x5F15;</span>
df2a = df2.set_index(<span class="hljs-string">&apos;name&apos;</span>)
df2a
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>date</th>
    </tr>
    <tr>
      <th>name</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>&#x674E;&#x56DB;</th>
      <td>2004</td>
    </tr>
    <tr>
      <th>&#x8D75;&#x516D;</th>
      <td>2008</td>
    </tr>
    <tr>
      <th>&#x5F20;&#x4E09;</th>
      <td>2012</td>
    </tr>
    <tr>
      <th>&#x738B;&#x4E94;</th>
      <td>2014</td>
    </tr>
  </tbody>
</table>
</div>



<p>&#x6309;&#x7D22;&#x5F15;&#x5408;&#x5E76;&#xFF0C;&#x6700;&#x7B80;&#x5355;&#x7684;&#x65B9;&#x5F0F; &#xFF1A;join()</p>
<pre><code class="lang-python"><span class="hljs-comment"># join&#x53EA;&#x7528;&#x4E8E;&#x4EE5;&#x884C;&#x7D22;&#x5F15;&#x4E3A;&#x57FA;&#x51C6;&#x5408;&#x5E76;</span>
df1a.join(df2a)
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>group</th>
      <th>date</th>
    </tr>
    <tr>
      <th>name</th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>&#x5F20;&#x4E09;</th>
      <td>DBA</td>
      <td>2012</td>
    </tr>
    <tr>
      <th>&#x674E;&#x56DB;</th>
      <td>PM</td>
      <td>2004</td>
    </tr>
    <tr>
      <th>&#x738B;&#x4E94;</th>
      <td>PM</td>
      <td>2014</td>
    </tr>
    <tr>
      <th>&#x8D75;&#x516D;</th>
      <td>HR</td>
      <td>2008</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python"><span class="hljs-comment"># merge&#x5B9E;&#x73B0;,&#x540C;&#x4E0A;</span>
pd.merge(df1a, df2a, left_index=<span class="hljs-keyword">True</span>, right_index=<span class="hljs-keyword">True</span>)
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>group</th>
      <th>date</th>
    </tr>
    <tr>
      <th>name</th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>&#x5F20;&#x4E09;</th>
      <td>DBA</td>
      <td>2012</td>
    </tr>
    <tr>
      <th>&#x674E;&#x56DB;</th>
      <td>PM</td>
      <td>2004</td>
    </tr>
    <tr>
      <th>&#x738B;&#x4E94;</th>
      <td>PM</td>
      <td>2014</td>
    </tr>
    <tr>
      <th>&#x8D75;&#x516D;</th>
      <td>HR</td>
      <td>2008</td>
    </tr>
  </tbody>
</table>
</div>



<p>&#x4E24;&#x6570;&#x636E;&#x7D22;&#x5F15;&#x5DEE;&#x5F02;&#x5DE8;&#x5927;&#xFF0C;&#x53C8;&#x5FC5;&#x987B;&#x4EE5;&#x4E00;&#x4E2A;&#x7D22;&#x5F15;&#x4E3A;&#x4E3B;&#x5408;&#x5E76;</p>
<pre><code class="lang-python"><span class="hljs-comment"># df1a&#xFF0C;&#x59D3;&#x540D;&#x548C;&#x5206;&#x7EC4;&#xFF0C;&#x59D3;&#x540D;&#x4E3A;&#x884C;&#x7D22;&#x5F15;</span>
df1a
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>group</th>
    </tr>
    <tr>
      <th>name</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>&#x5F20;&#x4E09;</th>
      <td>DBA</td>
    </tr>
    <tr>
      <th>&#x674E;&#x56DB;</th>
      <td>PM</td>
    </tr>
    <tr>
      <th>&#x738B;&#x4E94;</th>
      <td>PM</td>
    </tr>
    <tr>
      <th>&#x8D75;&#x516D;</th>
      <td>HR</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python"><span class="hljs-comment"># df6&#xFF0C;&#x59D3;&#x540D;2&#x548C;&#x85AA;&#x8D44;</span>
df6
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>username</th>
      <th>salary</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x738B;&#x4E94;</td>
      <td>10000</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>160000</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x8D75;&#x516D;</td>
      <td>7000</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x674E;&#x56DB;</td>
      <td>120000</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python"><span class="hljs-comment"># &#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x8868;&#x7684;&#x884C;&#x7D22;&#x5F15;&#x548C;&#x53E6;&#x4E00;&#x4E2A;&#x8868;&#x7684;&#x5217;&#x4E3A;&#x57FA;&#x51C6;&#x5408;&#x5E76;</span>
pd.merge(df1a, df6, left_index=<span class="hljs-keyword">True</span>, right_on=<span class="hljs-string">&apos;username&apos;</span>)
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>group</th>
      <th>username</th>
      <th>salary</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>1</th>
      <td>DBA</td>
      <td>&#x5F20;&#x4E09;</td>
      <td>160000</td>
    </tr>
    <tr>
      <th>3</th>
      <td>PM</td>
      <td>&#x674E;&#x56DB;</td>
      <td>120000</td>
    </tr>
    <tr>
      <th>0</th>
      <td>PM</td>
      <td>&#x738B;&#x4E94;</td>
      <td>10000</td>
    </tr>
    <tr>
      <th>2</th>
      <td>HR</td>
      <td>&#x8D75;&#x516D;</td>
      <td>7000</td>
    </tr>
  </tbody>
</table>
</div>



<hr>
<h1 id="&#x4E24;&#x4E2A;&#x5BF9;&#x5E94;&#x5217;&#x4E0D;&#x5B8C;&#x5168;&#x91CD;&#x590D;&#x7684;&#x6570;&#x636E;&#x96C6;&#x7684;&#x5408;&#x5E76;">&#x4E24;&#x4E2A;&#x5BF9;&#x5E94;&#x5217;&#x4E0D;&#x5B8C;&#x5168;&#x91CD;&#x590D;&#x7684;&#x6570;&#x636E;&#x96C6;&#x7684;&#x5408;&#x5E76;</h1>
<p>&#x53C2;&#x6570; how</p>
<ul>
<li>how=&apos;inner&apos;&#xFF0C;&#x4EA4;&#x96C6;&#xFF0C;&#x4E24;&#x4E2A;&#x8868;&#x5171;&#x6709;&#x7684;&#x884C;</li>
<li>how=&apos;outer&apos;&#xFF0C;&#x5E76;&#x96C6;&#xFF0C;&#x4E24;&#x4E2A;&#x8868;&#x6240;&#x6709;&#x7684;&#x884C;</li>
<li>how=&apos;left&apos;&#xFF0C;&#x8868;1&#x7684;&#x884C;</li>
<li>how=&apos;right&apos;&#xFF0C;&#x8868;2&#x7684;&#x884C;</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># df1&#xFF0C;&#x59D3;&#x540D;&#x548C;&#x5206;&#x7EC4;</span>
df1
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>group</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>DBA</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x674E;&#x56DB;</td>
      <td>PM</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x738B;&#x4E94;</td>
      <td>PM</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x8D75;&#x516D;</td>
      <td>HR</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python"><span class="hljs-comment"># df7&#xFF0C;&#x59D3;&#x540D;&#x548C;&#x65F6;&#x95F4;&#xFF0C;&#x59D3;&#x540D;&#x5217;&#x4E0D;&#x5B8C;&#x5168;&#x4E00;&#x81F4;</span>
df7 = pd.DataFrame({<span class="hljs-string">&apos;name&apos;</span>:[<span class="hljs-string">&apos;&#x5F20;&#x4E00;&apos;</span>, <span class="hljs-string">&apos;&#x674E;&#x4E8C;&apos;</span>, <span class="hljs-string">&apos;&#x8D75;&#x516D;&apos;</span>], <span class="hljs-string">&apos;data&apos;</span>:[<span class="hljs-number">2000</span>,<span class="hljs-number">2001</span>,<span class="hljs-number">2002</span>]})
df7
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>data</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x5F20;&#x4E00;</td>
      <td>2000</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x674E;&#x4E8C;</td>
      <td>2001</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x8D75;&#x516D;</td>
      <td>2002</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python">pd.merge(df1, df7)
pd.merge(df1, df7, how=<span class="hljs-string">&apos;inner&apos;</span>)  <span class="hljs-comment"># &#x4EA4;&#x96C6;</span>
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>group</th>
      <th>data</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x8D75;&#x516D;</td>
      <td>HR</td>
      <td>2002</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python">pd.merge(df1, df7, how=<span class="hljs-string">&apos;outer&apos;</span>)  <span class="hljs-comment"># &#x5E76;&#x96C6;</span>
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>group</th>
      <th>data</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>DBA</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x674E;&#x56DB;</td>
      <td>PM</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x738B;&#x4E94;</td>
      <td>PM</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x8D75;&#x516D;</td>
      <td>HR</td>
      <td>2002.0</td>
    </tr>
    <tr>
      <th>4</th>
      <td>&#x5F20;&#x4E00;</td>
      <td>NaN</td>
      <td>2000.0</td>
    </tr>
    <tr>
      <th>5</th>
      <td>&#x674E;&#x4E8C;</td>
      <td>NaN</td>
      <td>2001.0</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python">pd.merge(df1, df7, how=<span class="hljs-string">&apos;left&apos;</span>)  <span class="hljs-comment"># &#x4EE5;&#x5DE6;&#x8868;&#x4E3A;&#x57FA;&#x51C6;</span>
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>group</th>
      <th>data</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>DBA</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x674E;&#x56DB;</td>
      <td>PM</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x738B;&#x4E94;</td>
      <td>PM</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x8D75;&#x516D;</td>
      <td>HR</td>
      <td>2002.0</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python">pd.merge(df1, df7, how=<span class="hljs-string">&apos;right&apos;</span>)  <span class="hljs-comment"># &#x4EE5;&#x53F3;&#x8868;&#x4E3A;&#x57FA;&#x51C6;</span>
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>group</th>
      <th>data</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x8D75;&#x516D;</td>
      <td>HR</td>
      <td>2002</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x5F20;&#x4E00;</td>
      <td>NaN</td>
      <td>2000</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x674E;&#x4E8C;</td>
      <td>NaN</td>
      <td>2001</td>
    </tr>
  </tbody>
</table>
</div>



<h1 id="&#x5408;&#x5E76;&#x6570;&#x636E;&#x96C6;&#x4E2D;&#x5305;&#x542B;&#x4E24;&#x4E2A;&#x6216;&#x4EE5;&#x4E0A;&#x76F8;&#x540C;&#x5217;&#x540D;&#x65F6;">&#x5408;&#x5E76;&#x6570;&#x636E;&#x96C6;&#x4E2D;&#x5305;&#x542B;&#x4E24;&#x4E2A;&#x6216;&#x4EE5;&#x4E0A;&#x76F8;&#x540C;&#x5217;&#x540D;&#x65F6;</h1>
<p>&#x53C2;&#x6570; on &#x6307;&#x5B9A;&#x7528;&#x4E8E;&#x5408;&#x5E76;&#x7684;&#x4E3B;&#x952E;</p>
<p>&#x5408;&#x5E76;&#x540E;&#x7684;&#x6570;&#x636E;&#x96C6;&#x4E2D;&#xFF0C;&#x4E4B;&#x524D;&#x76F8;&#x540C;&#x7684;&#x5217;&#x540D;&#x4F1A;&#x88AB;&#x9ED8;&#x8BA4;&#x52A0;&#x4E0A; _x &#x7B49;&#x540E;&#x7F00;&#x7528;&#x4E8E;&#x533A;&#x5206;</p>
<p>&#x53C2;&#x6570; suffixes &#x53EF;&#x4EE5;&#x81EA;&#x5B9A;&#x4E49;&#x540E;&#x7F00;</p>
<pre><code class="lang-python"><span class="hljs-comment"># df1&#xFF0C;&#x59D3;&#x540D;&#x548C;&#x5206;&#x7EC4;</span>
df1
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>group</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>DBA</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x674E;&#x56DB;</td>
      <td>PM</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x738B;&#x4E94;</td>
      <td>PM</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x8D75;&#x516D;</td>
      <td>HR</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python"><span class="hljs-comment"># df8&#xFF0C;&#x76F8;&#x540C;&#x7684;&#x59D3;&#x540D;&#x548C;&#x5206;&#x7EC4;</span>
df8 = pd.DataFrame({
    <span class="hljs-string">&apos;name&apos;</span>: [<span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>, <span class="hljs-string">&apos;&#x738B;&#x4E94;&apos;</span>, <span class="hljs-string">&apos;&#x8D75;&#x516D;&apos;</span>, <span class="hljs-string">&apos;&#x674E;&#x56DB;&apos;</span>],
    <span class="hljs-string">&apos;group&apos;</span>: [<span class="hljs-string">&apos;code&apos;</span>, <span class="hljs-string">&apos;VP&apos;</span>,<span class="hljs-string">&apos;VP&apos;</span>, <span class="hljs-string">&apos;code&apos;</span>]
})
df8
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>group</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>code</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x738B;&#x4E94;</td>
      <td>VP</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x8D75;&#x516D;</td>
      <td>VP</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x674E;&#x56DB;</td>
      <td>code</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python">pd.merge(df1, df8, on=<span class="hljs-string">&apos;name&apos;</span>)  <span class="hljs-comment"># &#x4E24;&#x8868;&#x8D85;&#x8FC7;1&#x4E2A;&#x5217;&#x540D;&#x76F8;&#x540C;&#xFF0C;&#x624B;&#x52A8;&#x6307;&#x5B9A;&#x5408;&#x5E76;&#x57FA;&#x51C6;&#x5217;</span>
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>group_x</th>
      <th>group_y</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>DBA</td>
      <td>code</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x674E;&#x56DB;</td>
      <td>PM</td>
      <td>code</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x738B;&#x4E94;</td>
      <td>PM</td>
      <td>VP</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x8D75;&#x516D;</td>
      <td>HR</td>
      <td>VP</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python"><span class="hljs-comment"># &#x901A;&#x8FC7;&#x8BBE;&#x7F6E;&#x53C2;&#x6570; suffixes &#x81EA;&#x5B9A;&#x4E49;&#x540E;&#x7F00;</span>
pd.merge(df1, df8, on=<span class="hljs-string">&apos;name&apos;</span>, suffixes=[<span class="hljs-string">&apos;_L&apos;</span>, <span class="hljs-string">&apos;_R&apos;</span>])
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>name</th>
      <th>group_L</th>
      <th>group_R</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>&#x5F20;&#x4E09;</td>
      <td>DBA</td>
      <td>code</td>
    </tr>
    <tr>
      <th>1</th>
      <td>&#x674E;&#x56DB;</td>
      <td>PM</td>
      <td>code</td>
    </tr>
    <tr>
      <th>2</th>
      <td>&#x738B;&#x4E94;</td>
      <td>PM</td>
      <td>VP</td>
    </tr>
    <tr>
      <th>3</th>
      <td>&#x8D75;&#x516D;</td>
      <td>HR</td>
      <td>VP</td>
    </tr>
  </tbody>
</table>
</div>



<h1 id="&#x5408;&#x5E76;&#x91CD;&#x53E0;&#x6570;&#x636E;">&#x5408;&#x5E76;&#x91CD;&#x53E0;&#x6570;&#x636E;</h1>
<p>&#x6709;&#x4E00;&#x7C7B;&#x6570;&#x636E;&#x7EC4;&#x5408;&#x95EE;&#x9898;&#x4E0D;&#x80FD;&#x7528;&#x7B80;&#x5355;&#x7684;&#x5408;&#x5E76;&#xFF08;merge&#xFF09;&#x6216;&#x8FDE;&#x63A5;&#xFF08;concatenation(concat)&#xFF09;&#x8FD0;&#x7B97;&#x6765;&#x5904;&#x7406;&#x3002; &#x5982;&#x5408;&#x5E76;&#x5168;&#x90E8;&#x6216;&#x90E8;&#x5206;&#x91CD;&#x53E0;&#x7684;&#x4E24;&#x4E2A;&#x6570;&#x636E;&#x96C6;</p>
<p>&#x4E3E;&#x4F8B;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;NumPy&#x7684;where&#x51FD;&#x6570;&#xFF0C;&#x5B83;&#x8868;&#x793A;&#x4E00;&#x79CD;&#x7B49;&#x4EF7;&#x4E8E;&#x9762;&#x5411;&#x6570;&#x7EC4;&#x7684;if-else</p>
<h1 id="&#x4EE5;a&#x4E3A;&#x57FA;&#x51C6;&#x5408;&#x5E76;&#xFF0C;a&#x7684;&#x7F3A;&#x5931;&#x503C;&#x4F7F;&#x7528;b&#x586B;&#x5145;">&#x4EE5;a&#x4E3A;&#x57FA;&#x51C6;&#x5408;&#x5E76;&#xFF0C;a&#x7684;&#x7F3A;&#x5931;&#x503C;&#x4F7F;&#x7528;b&#x586B;&#x5145;</h1>
<p>&#x5148;&#x7ED9;a&#x6253;&#x8865;&#x4E01;&#xFF08;&#x7528;b&#x586B;&#x5145;a&#x7684;&#x7F3A;&#x5931;&#x503C;&#xFF0C;&#x518D;&#x5408;&#x5E76;&#xFF09;</p>
<pre><code class="lang-python">a = pd.Series([np.nan, <span class="hljs-number">2.5</span>, np.nan, <span class="hljs-number">3.5</span>, <span class="hljs-number">4.5</span>, np.nan], index=[<span class="hljs-string">&apos;f&apos;</span>, <span class="hljs-string">&apos;e&apos;</span>, <span class="hljs-string">&apos;d&apos;</span>, <span class="hljs-string">&apos;c&apos;</span>, <span class="hljs-string">&apos;b&apos;</span>, <span class="hljs-string">&apos;a&apos;</span>])
b = pd.Series(np.arange(len(a), dtype=np.float64), index=[<span class="hljs-string">&apos;f&apos;</span>, <span class="hljs-string">&apos;e&apos;</span>, <span class="hljs-string">&apos;d&apos;</span>, <span class="hljs-string">&apos;c&apos;</span>, <span class="hljs-string">&apos;b&apos;</span>, <span class="hljs-string">&apos;a&apos;</span>])
b[-<span class="hljs-number">1</span>] = np.nan
</code></pre>
<pre><code class="lang-python">a
</code></pre>
<pre><code>f    NaN
e    2.5
d    NaN
c    3.5
b    4.5
a    NaN
dtype: float64
</code></pre><pre><code class="lang-python">b
</code></pre>
<pre><code>f    0.0
e    1.0
d    2.0
c    3.0
b    4.0
a    NaN
dtype: float64
</code></pre><p>&#x5C06;a&#x7684;&#x7F3A;&#x5931;&#x503C;&#x4F7F;&#x7528;b&#x586B;&#x5145;</p>
<pre><code class="lang-python">a.isnull()
</code></pre>
<pre><code>f     True
e    False
d     True
c    False
b    False
a     True
dtype: bool
</code></pre><pre><code class="lang-python"><span class="hljs-comment"># &#x65B9;&#x6CD5;1</span>
np.where(a.isnull(), b, a)
</code></pre>
<pre><code>array([0. , 2.5, 2. , 3.5, 4.5, nan])
</code></pre><pre><code class="lang-python"><span class="hljs-comment"># &#x65B9;&#x6CD5;2</span>
ax = a.copy()
ax

ax[ax.isnull()] = b
ax
</code></pre>
<pre><code>f    0.0
e    2.5
d    2.0
c    3.5
b    4.5
a    NaN
dtype: float64
</code></pre><p>Series&#x6709;&#x4E00;&#x4E2A;combine_first&#x65B9;&#x6CD5;&#xFF0C;&#x5B9E;&#x73B0;&#x7684;&#x4E5F;&#x662F;&#x7C7B;&#x4F3C;&#x529F;&#x80FD;&#xFF0C;</p>
<p>&#x9664;&#x4E86;&#x7528;b&#x586B;&#x5145;a&#x7684;&#x7F3A;&#x5931;&#x503C;&#xFF0C;&#x8FD8;&#x5E26;&#x6709;pandas&#x6570;&#x636E;&#x5BF9;&#x9F50;&#x7684;&#x5408;&#x5E76;&#x529F;&#x80FD;</p>
<h2 id="&#x4F8B;&#x5B50;&#xFF1A;&#x4EE5;a2&#x4E3A;&#x57FA;&#x51C6;&#x5408;&#x5E76;&#xFF0C;a2&#x7F3A;&#x5931;&#x6570;&#x636E;&#x4F7F;&#x7528;b2&#x586B;&#x5145;">&#x4F8B;&#x5B50;&#xFF1A;&#x4EE5;a2&#x4E3A;&#x57FA;&#x51C6;&#x5408;&#x5E76;&#xFF0C;a2&#x7F3A;&#x5931;&#x6570;&#x636E;&#x4F7F;&#x7528;b2&#x586B;&#x5145;</h2>
<pre><code class="lang-python">a2 = a[<span class="hljs-number">2</span>:]
a2
</code></pre>
<pre><code>d    NaN
c    3.5
b    4.5
a    NaN
dtype: float64
</code></pre><pre><code class="lang-python">b2 = b[:-<span class="hljs-number">2</span>]
b2
</code></pre>
<pre><code>f    0.0
e    1.0
d    2.0
c    3.0
dtype: float64
</code></pre><p>&#x4F7F;&#x7528;&#x539F;&#x751F;&#x65B9;&#x5F0F;&#x6253;&#x8865;&#x4E01;</p>
<pre><code class="lang-python">
a22 = a2.copy()
a22[a22.isnull()] = b2
a22
</code></pre>
<pre><code>d    2.0
c    3.5
b    4.5
a    NaN
dtype: float64
</code></pre><p>&#x4F7F;&#x7528;combine_first&#x65B9;&#x6CD5;&#xFF0C;&#x5148;&#x6253;&#x8865;&#x4E01;&#xFF0C;&#x518D;&#x5408;&#x5E76;</p>
<pre><code class="lang-python">a2.combine_first(b2)
</code></pre>
<pre><code>a    NaN
b    4.5
c    3.5
d    2.0
e    1.0
f    0.0
dtype: float64
</code></pre><h3 id="&#x5BF9;&#x4E8E;dataframe&#xFF0C;combinefirst&#x4F1A;&#x5728;&#x5217;&#x4E0A;&#x5E94;&#x7528;&#x540C;&#x6837;&#x64CD;&#x4F5C;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x5176;&#x770B;&#x505A;&#xFF1A;">&#x5BF9;&#x4E8E;DataFrame&#xFF0C;combine_first&#x4F1A;&#x5728;&#x5217;&#x4E0A;&#x5E94;&#x7528;&#x540C;&#x6837;&#x64CD;&#x4F5C;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x5176;&#x770B;&#x505A;&#xFF1A;</h3>
<p>&#x7528;&#x4F20;&#x9012;&#x5BF9;&#x8C61;&#x4E2D;&#x7684;&#x6570;&#x636E;&#x4E3A;&#x8C03;&#x7528;&#x5BF9;&#x8C61;&#x7684;&#x7F3A;&#x5931;&#x6570;&#x636E;&#x201C;&#x6253;&#x8865;&#x4E01;&#x201D;</p>
<pre><code class="lang-python">df11 = pd.DataFrame({<span class="hljs-string">&apos;a&apos;</span>: [<span class="hljs-number">1.</span>, np.nan, <span class="hljs-number">5.</span>, np.nan], <span class="hljs-string">&apos;b&apos;</span>: [np.nan, <span class="hljs-number">2.</span>, np.nan, <span class="hljs-number">6.</span>], <span class="hljs-string">&apos;c&apos;</span>: range(<span class="hljs-number">2</span>, <span class="hljs-number">18</span>, <span class="hljs-number">4</span>)})
df21 = pd.DataFrame({<span class="hljs-string">&apos;a&apos;</span>: [<span class="hljs-number">5.</span>, <span class="hljs-number">4.</span>, np.nan, <span class="hljs-number">3.</span>, <span class="hljs-number">7.</span>], <span class="hljs-string">&apos;b&apos;</span>: [np.nan, <span class="hljs-number">3.</span>, <span class="hljs-number">4.</span>, <span class="hljs-number">6.</span>, <span class="hljs-number">8.</span>]})
</code></pre>
<pre><code class="lang-python">df11
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>a</th>
      <th>b</th>
      <th>c</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>1.0</td>
      <td>NaN</td>
      <td>2</td>
    </tr>
    <tr>
      <th>1</th>
      <td>NaN</td>
      <td>2.0</td>
      <td>6</td>
    </tr>
    <tr>
      <th>2</th>
      <td>5.0</td>
      <td>NaN</td>
      <td>10</td>
    </tr>
    <tr>
      <th>3</th>
      <td>NaN</td>
      <td>6.0</td>
      <td>14</td>
    </tr>
  </tbody>
</table>
</div>




<pre><code class="lang-python">df21
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>a</th>
      <th>b</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>5.0</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>1</th>
      <td>4.0</td>
      <td>3.0</td>
    </tr>
    <tr>
      <th>2</th>
      <td>NaN</td>
      <td>4.0</td>
    </tr>
    <tr>
      <th>3</th>
      <td>3.0</td>
      <td>6.0</td>
    </tr>
    <tr>
      <th>4</th>
      <td>7.0</td>
      <td>8.0</td>
    </tr>
  </tbody>
</table>
</div>



<h3 id="&#x4EE5;df11&#x4E3A;&#x57FA;&#x51C6;&#xFF0C;&#x5148;&#x586B;&#x5145;&#x7F3A;&#x5931;&#x503C;&#xFF08;&#x7528;df21&#x7684;&#x503C;&#x586B;&#x5145;df11&#xFF09;&#xFF0C;&#x518D;&#x5408;&#x5E76;df21&#x7684;&#x591A;&#x4F59;&#x884C;&#x5217;&#x5408;&#x5E76;&#x5230;df11&#x4E0A;">&#x4EE5;df11&#x4E3A;&#x57FA;&#x51C6;&#xFF0C;&#x5148;&#x586B;&#x5145;&#x7F3A;&#x5931;&#x503C;&#xFF08;&#x7528;df21&#x7684;&#x503C;&#x586B;&#x5145;df11&#xFF09;&#xFF0C;&#x518D;&#x5408;&#x5E76;(df21&#x7684;&#x591A;&#x4F59;&#x884C;&#x5217;&#x5408;&#x5E76;&#x5230;df11&#x4E0A;)</h3>
<pre><code class="lang-python">df11.combine_first(df21)
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>a</th>
      <th>b</th>
      <th>c</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>1.0</td>
      <td>NaN</td>
      <td>2.0</td>
    </tr>
    <tr>
      <th>1</th>
      <td>4.0</td>
      <td>2.0</td>
      <td>6.0</td>
    </tr>
    <tr>
      <th>2</th>
      <td>5.0</td>
      <td>4.0</td>
      <td>10.0</td>
    </tr>
    <tr>
      <th>3</th>
      <td>3.0</td>
      <td>6.0</td>
      <td>14.0</td>
    </tr>
    <tr>
      <th>4</th>
      <td>7.0</td>
      <td>8.0</td>
      <td>NaN</td>
    </tr>
  </tbody>
</table>
</div>



<h3 id="&#x4EE5;df21&#x4E3A;&#x57FA;&#x51C6;&#xFF0C;&#x5148;&#x586B;&#x5145;&#xFF08;&#x7528;df11&#x7684;&#x503C;&#x586B;&#x5145;df21&#xFF09;&#xFF0C;&#x518D;&#x5408;&#x5E76;">&#x4EE5;df21&#x4E3A;&#x57FA;&#x51C6;&#xFF0C;&#x5148;&#x586B;&#x5145;&#xFF08;&#x7528;df11&#x7684;&#x503C;&#x586B;&#x5145;df21&#xFF09;&#xFF0C;&#x518D;&#x5408;&#x5E76;</h3>
<pre><code class="lang-python">df21.combine_first(df11)
</code></pre>
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>a</th>
      <th>b</th>
      <th>c</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>5.0</td>
      <td>NaN</td>
      <td>2.0</td>
    </tr>
    <tr>
      <th>1</th>
      <td>4.0</td>
      <td>3.0</td>
      <td>6.0</td>
    </tr>
    <tr>
      <th>2</th>
      <td>5.0</td>
      <td>4.0</td>
      <td>10.0</td>
    </tr>
    <tr>
      <th>3</th>
      <td>3.0</td>
      <td>6.0</td>
      <td>14.0</td>
    </tr>
    <tr>
      <th>4</th>
      <td>7.0</td>
      <td>8.0</td>
      <td>NaN</td>
    </tr>
  </tbody>
</table>
</div>



                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../数据分析库的操作/14Pandas数据规整-转换-离散化和面元划分.html" class="navigation navigation-prev " aria-label="Previous page: 离散化和面元划分"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../数据分析库的操作/13Pandas数据规整-重塑和轴向旋转.html" class="navigation navigation-next " aria-label="Next page: Pandas数据规整-重塑和轴向旋转"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
